import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import net.shopxx.entity.AirOrder;
import net.shopxx.entity.Flight;
import net.shopxx.entity.LinkerInfo;
import net.shopxx.entity.Member;
import net.shopxx.entity.OrderInfo;
import net.shopxx.entity.Passenger;
import net.shopxx.entity.Price;
import net.shopxx.entity.Properties;
import net.shopxx.entity.PropertiesValue;
import net.shopxx.entity.AirOrder.OrderStatus;
import net.shopxx.entity.AirOrder.PaymentStatus;
import net.shopxx.service.OrderPointerService;
import net.shopxx.service.PropertiesService;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.FileSystemXmlApplicationContext;


public class ServiceTest {
	@SuppressWarnings("unchecked")
	public static void main(String[] args) {
		
		ApplicationContext ctx = 
//			new ClassPathXmlApplicationContext(new String[]{
//				"applicationContext.xml","applicationContext-compass.xml","applicationContext-security.xml"});
			new FileSystemXmlApplicationContext(
				new String[] { "/WebRoot/WEB-INF/applicationContext.xml"
						,"/WebRoot/WEB-INF/applicationContext-compass.xml"
						,"/WebRoot/WEB-INF/applicationContext-security.xml" 
						});
		
		PropertiesService service = (PropertiesService)ctx.getBean("propertiesServiceImpl");
		
		Properties properties = new Properties();
		properties.setEnumLable("不知道");
		
		List<PropertiesValue> list = new ArrayList<PropertiesValue>();
		
		for (int i=0; i < 5; i++) {
			PropertiesValue value = new PropertiesValue();
			value.setProperties(properties);
			value.setLable("b_"+i);
			value.setValue(""+i);
			list.add(value);
		}
		properties.setPropertiesValueList(list);
		service.save(properties);
//		Member member1 = new Member();
//		member1.setId("4028818c38576d1e01385778a9b20001");
//		Pager pager = new Pager();
//		List<OrderItem> ls1 =service.getOrderItemList(member1,pager).getList();
//		List<Properties> ls = service.getAll();
//		for (Properties orderItem :ls) {
//			System.out.println(orderItem.getEnumLable());
//		}
		
//		for (ProductCategory productCategory : goods) {
//			if(productCategory.getId().equalsIgnoreCase("402881882ba8753a012ba952154601c0"))
//			{
//				for (Properties properties : productCategory.getPropertiesSet().toArray(new Properties[]{})) {
//					System.out.println(properties.getPropertiesValueList()
//							.size());;
//				}
//			}
//		}
//		ProductService adminService = (ProductService) ctx.getBean("productServiceImpl");
//		Product product = new Product();
		
		
//		Product product = adminService.load("402881862bee2228012bee40a24d0008");
//		System.out.println(product.getName());
//		for (ProductProperties productProperties : product.getProductPropertiesList()) {
//			System.out.println(productProperties.getLable());
//			System.out.println(productProperties.getProperties().getPropertiesValueList().get(0).getValue());
//		}
//		System.out
//				.println(product.getProductColorList().get(0).getImgUrl());
//		
		
//		ColorService colorService = (ColorService) ctx.getBean("colorServiceImpl");
//		List<Color> list = colorService.getAll();
//		
//		for (Color color : list) {
//			System.out
//			.println(color.getName()+":"+color.getLogo());
//		}
//		
//		Color color = new Color();
//		color.setName("蓝色");
//		color.setLogo("/img/1.jpg");
//		color.setOrderList(1);
//		
//		adminService.save(color);
		
		
		if(true)
			return;
		
//		BaseService  service = (BaseService) ctx.getBean("flagshipStoreServiceImpl");
//		service.l
//		ProductService  service = (ProductService) ctx.getBean("productServiceImpl");
//		OrderService  service = (OrderService) ctx.getBean("orderServiceImpl");
//		MemberService service = (MemberService) ctx.getBean("memberServiceImpl");
//		ProductCategoryService pservice = (ProductCategoryService) ctx.getBean("productCategoryServiceImpl");
//		List<ProductCategory> ls = service.getRootProductCategoryList();
//		FlagshipStore entity = new FlagshipStore();
//		String id = "1224ddndfdfaf";
//		String mid ="4028818c38576d1e01385778a9b20001";
//		Member member = service.get("mid");
//		System.out.println(member.getFlagshipStore().getStore_name());
		
//		entity = (FlagshipStore)service.get(id);
//		entity.setStore_name("222");
//		service.update(entity);
		
//		String id = UUID.randomUUID().toString();
//		entity.setId(id.length()>32?id.substring(0, 32):id);
//		Member meber = new Member();
//		meber.setId("4028818c38576d1e01385778a9b20001");
//		entity.setMember(meber);
//		entity.setStatus("0");
//		entity.setStore_banner("/bath/1.png");
//		entity.setStore_logo("/bath/2.png");
//		service.save(entity);
//		List<FlagshipStore> ls = service.getAll();
//		System.out.println(ls.size());
//		
//		IndexfloorService service = (IndexfloorService)ctx.getBean("indexfloorServiceImpl");
//		Pager pager = new Pager();
//		service.findByPager(pager);
//		System.out.println(pager.getList().size());
		
//		ProductConsultService pservice = (ProductConsultService) ctx.getBean("productConsultServiceImpl");
////		Product product = service.get("402881882badb4ed012bae65af360036");		
//		Member member = service.get("4028818c38576d1e01385778a9b20001");
//		Pager pager = new Pager();
//		pager.setPageSize(100);
////		pservice.getProductConsultPager(product, pager);
//		pservice.getMemberConsultPager(member, pager);
//		List<ProductConsult> ls = (List<ProductConsult>)pager.getList();
//		for (ProductConsult obj : ls) {
//			System.out.println(obj.getContent());
//		}
		
		
//		List<Brand> ls = service.getBrandList(productCategory);
//		for (ProductCategory product : ls) {
//			System.out.println(product.getCategroyIcon());
//		}
		
//		System.out.println("list size is " + service.getAll().size());
//		System.out.println(DigestUtils.md5Hex("admin"));
//		ProductService  productService = (ProductService) ctx.getBean("productServiceImpl");
//		Product product = productService.get("402881882badb4ed012bae65af360036");		
//		MemberService memberService = (MemberService) ctx.getBean("memberServiceImpl");
//		Member member = memberService.get("4028818c38576d1e01385778a9b20001");
//		CartItemService  service = (CartItemService) ctx.getBean("cartItemServiceImpl");
//
//		GroupbuyService  groupbuyService = (GroupbuyService) ctx.getBean("groupbuyServiceImpl");
//		Groupbuy groupbuy = groupbuyService.get("402881823918d6ef013918dccbe90002");		
//		CartItemProduct cartItem = new CartItemProduct();
//		cartItem.setQuantity(2);
//		cartItem.setMember(member);
//		cartItem.setProduct(product);
//		service.save(cartItem);
//		
//		CartItemGroupbuy cartItem = new CartItemGroupbuy();
//		cartItem.setQuantity(2);
//		cartItem.setMember(member);
//		cartItem.setGroupbuy(groupbuy);
//		service.save(cartItem);
		
//		for (CartItem item : service.getAll()) {
//			if(item instanceof CartItemProduct)
//			{
//				CartItemProduct productItem = (CartItemProduct)item;
//				System.out.println(productItem.getProduct().getName());
//			}
//			else if(item instanceof CartItemGroupbuy)
//			{
//				CartItemGroupbuy productItem = (CartItemGroupbuy)item;
//				System.out.println(productItem.getGroupbuy().getName());
//			}
//		}
		
//		AirportService  service = (AirportService) ctx.getBean("airportServiceImpl");
//		Airport airport = new Airport();
//		
//		AirCompanyService  service = (AirCompanyService) ctx.getBean("airCompanyServiceImpl");
//		
//		List<AirCompany> ls = service.getAll();
//		
//		for (AirCompany airportObj : ls) {
//			System.out.println(airportObj.getName());
//		}
		
//		AirOrderService service = (AirOrderService)ctx.getBean("airOrderServiceImpl");
		OrderPointerService orderPointerService = (OrderPointerService)ctx.getBean("orderPointerServiceImpl");
		AirOrder airOrder = new AirOrder();
		
		LinkerInfo linkerInfo = new LinkerInfo();
		linkerInfo.setLinkerName("zhangsan");
		airOrder.setLinkerInfo(linkerInfo);
		
		Flight flight = new Flight();
		flight.setFlightNo("CZ20112");
		flight.setAirOrder(airOrder);
		Set<Flight> setFlight = new HashSet<Flight>();
		setFlight.add(flight);
		airOrder.setFlightSet(setFlight);
		
		
		Passenger passenger = new Passenger();
		passenger.setName("张三");
		passenger.setAirOrder(airOrder);
		Set<Passenger> passengerSet = new HashSet<Passenger>();
		passengerSet.add(passenger);
		airOrder.setPassengerSet(passengerSet);

		Price price = new Price();
		price.setFare(1.0f);
		price.setAirOrder(airOrder);
//		airOrder.addPriceSet(price);
		Set<Price> priceSet = new HashSet<Price>();
		priceSet.add(price);
		airOrder.setPriceSet(priceSet);
		
		OrderInfo orderInfo = new OrderInfo();
		orderInfo.setIsDomc("D");
		orderInfo.setCustomerNo("22324");
		airOrder.setOrderInfo(orderInfo);
		Member member = new Member();
		member.setId("4028818c38576d1e01385778a9b20001");
		airOrder.setMember(member);
		
		airOrder.setDeliveryFee(new BigDecimal("22"));
		airOrder.setDeliveryTypeName("yT");
		airOrder.setPaymentFee(new BigDecimal("1500"));
		airOrder.setTotalAmount(new BigDecimal("1800"));
		airOrder.setPaymentStatus(PaymentStatus.paid);
		airOrder.setProductTotalPrice(new BigDecimal("1800"));
		airOrder.setOrderSn("001");
		airOrder.setOrderStatus(OrderStatus.processed);
		airOrder.setPaymentConfigName("noName");
//		service.save(airOrder);
		
//		List<OrderPointer> ls = orderPointerService.getAll();
//		
//		for (OrderPointer airOrderTemp : ls) {
//			System.out.println(airOrderTemp.getOrderSn());
//		}
		
		
		
		
		
	}
}
